package com.sskj.gcc.ui.activity;

import android.graphics.Color;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.alibaba.android.arouter.facade.annotation.Autowired;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.bulong.rudeness.RudenessScreenHelper;
import com.shizhefei.mvc.MVCCoolHelper;
import com.shizhefei.view.coolrefreshview.CoolRefreshView;
import com.sskj.common.base.App;
import com.sskj.gocoin.R2;
import com.sskj.gocoin.adapter.slimadapter.IViewInjector;
import com.sskj.gocoin.adapter.slimadapter.SlimAdapter;
import com.sskj.gocoin.adapter.slimadapter.SlimInjector;
import com.sskj.gocoin.common.decoration.DividerLineItemDecoration;
import com.sskj.gocoin.mvchelper.ModelRx2DataSource;
import com.sskj.gcc.R;
import com.sskj.gcc.bean.MiningLjRecord;
import com.sskj.gcc.presenter.MiningRecordPresenter;
import com.sskj.lib.RConfig;
import com.sskj.lib.base.BaseActivity;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;


@Route(path = RConfig.APP_SY_RECORD)  //累计收益明细
public class MiningRecordActivity extends BaseActivity<MiningRecordPresenter> {

    @BindView(R2.id.recyclerView)
    RecyclerView recyclerView;
    @BindView(R2.id.coolRefreshView)
    CoolRefreshView coolRefreshView;
    @Autowired
    public String type;
    private SlimAdapter<MiningLjRecord.LJRecord> slimAdapter;
    private MVCCoolHelper<List<MiningLjRecord.LJRecord>> mvcCoolHelper;


    @Override
    protected int getLayoutResId() {
        return R.layout.app_activity_mining_record;
    }

    @Override
    public MiningRecordPresenter getPresenter() {
        return new MiningRecordPresenter();
    }

    @Override
    protected void initView() {
        ARouter.getInstance().inject(this);
        setTitle(App.INSTANCE.getString(R.string.appJavaMiningRecordActivity1) + (type.equals("usdt_num") ? "(USDT)" : "(IM COIN)"));
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        recyclerView.addItemDecoration(new DividerLineItemDecoration(this)
                .setFirstDraw(false)
                .setLastDraw(false)
                .setDividerColor(ContextCompat.getColor(App.INSTANCE,R.color.app_divider))
                .setPaintWidth((int) RudenessScreenHelper.pt2px(this, 1)));
        slimAdapter = SlimAdapter.create().register(R.layout.app_item_share, new SlimInjector<MiningLjRecord.LJRecord>() {
            @Override
            public void onInject(MiningLjRecord.LJRecord data, IViewInjector injector) {
                injector.text(R.id.tv_item_num, "+"+data.getNum())
                        .text(R.id.time, data.getTime());
                int taskInt = Integer.parseInt(data.getTask());
                if(taskInt==0){
                    injector.text(R.id.name,getString(R.string.mining_wklq));
                }else if(taskInt==4){
                    injector.text(R.id.name,getString(R.string.mining_rwlq));
                }else if(taskInt==5){
                    injector.text(R.id.name,getString(R.string.mining_yqlq));
                }else if(taskInt==7){
                    injector.text(R.id.name, getString(R.string.mining_jyfy));
                }else if(taskInt==8){
                    injector.text(R.id.name,getString(R.string.mining_xjfy));
                }else if(taskInt>30){
                    injector.text(R.id.name,getString(R.string.mining_czrw));
                }
            }
        }).attachTo(recyclerView).updateData(new ArrayList());
        ModelRx2DataSource<MiningLjRecord.LJRecord> dataSource =
                new ModelRx2DataSource<>((ModelRx2DataSource.OnLoadSource<MiningLjRecord.LJRecord>)
                        page -> mPresenter.getList(page, 15, type,"0"), 15);
        mvcCoolHelper = new MVCCoolHelper<>(coolRefreshView);
        mvcCoolHelper.setDataSource(dataSource);
        mvcCoolHelper.setAdapter(slimAdapter);
        mvcCoolHelper.refresh();
    }


    @Override
    public boolean getImmersion() {
        return false;
    }
}
